<%-- 
    Document   : question-manage-action
    Created on : Feb 16, 2012, 9:56:05 AM
    Author     : PhucAn
--%>
<%@page import="dao.ExamDAO"%>
<%@page import="dto.Exam"%>
<%@page import="util.PagingUtil"%>
<%@page import="util.SharingUtil"%>
<%@page import="dto.Question"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dao.QuestionDAO"%>
<%
    QuestionDAO daoQuestion = new QuestionDAO();
    boolean useSearch = false;
    String searchContent = null;
    String st = request.getParameter("selected-item-id");
    if (st != null) {
        if (!st.equals("")) {
            daoQuestion.delete(Integer.parseInt(st));
        }
    }
    ArrayList<Question> list = new ArrayList<Question>();
    int currentPage = PagingUtil.getPageNumber(request.getParameter("page"));
    int total = 0;
    String pagingNav = "";
    if (request.getParameter("search") != null) {
        if (!request.getParameter("search").equals("")) {
            searchContent = request.getParameter("search");
            list = daoQuestion.getQuestions(currentPage, PagingUtil.CONST_PAGE_SIZE, searchContent);
            request.setAttribute("search", searchContent);
            useSearch = true;
        } else {
            list = daoQuestion.getQuestions(currentPage, PagingUtil.CONST_PAGE_SIZE);
        }
    } else {
        list = daoQuestion.getQuestions(currentPage, PagingUtil.CONST_PAGE_SIZE);
    }
    total = daoQuestion.getTotalRecords();
    //this value is use for paging
    String requestString = "?pcontent=manage-question&page=";
    if (useSearch) {
        requestString += "&search=" + searchContent;
    }
    pagingNav = PagingUtil.getPageNavigator(total, PagingUtil.CONST_PAGE_SIZE, currentPage, requestString);
    request.setAttribute("list", list);
    request.setAttribute("pagingNav", pagingNav);
//exam
    String strExam=request.getParameter("exid");
    if(strExam!=null){
        int exid=Integer.parseInt(strExam);
        ExamDAO daoExam=new ExamDAO();
        Exam exam=daoExam.getExam(exid);
        SharingUtil.setCurrentExam(session, exam);
    }
%>
